package com.weiqiao.api.rest;


import com.weiqiao.aop.log.Log;
import com.weiqiao.api.domain.*;
import com.weiqiao.api.domain.vo.AppUserVo;
import com.weiqiao.api.domain.vo.ReceiptApiVO;
import com.weiqiao.api.service.IAppUserApiService;
import com.weiqiao.api.until.ApiResUtil;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping(value = "mallApi/appUser/api")
public class AppUserApiController {


    @Autowired
    private IAppUserApiService appUserApiService;

    @Log("获取用户信息")
    @GetMapping("/user/get-user-info")
    public ApiResponseEntity getUserInfo(@Validated AppUserVo vo) {
        Bson filter = new Document("user_id", vo.getUser_id());
        AppUserApiEntity info =  appUserApiService.getUser(vo.getCompany_id(), filter);
        return ApiResUtil.buildRes(true, "", info);
    }

    @Log("积分流水")
    @GetMapping("/user/score-history")
    public ApiResponseEntity getScoreHistory(@Validated AppUserVo vo) {
        List<AccountDetailApiEntity> list =  appUserApiService.findAccountDetailsByFilter(vo);
        return ApiResUtil.buildRes(true, "", list);
    }

    @Log("获取提现起提金额")
    @GetMapping("/user/withdrawal-config")
    public ApiResponseEntity getWithdrawalConfig(@Validated AppUserVo vo) {
        return ApiResUtil.buildRes(true, "", appUserApiService.getWithdrawalLimit(vo));
    }

    @Log("提现")
    @PostMapping("/user/user-withdrawal")
    public ApiResponseEntity userWithdrawal(@RequestBody @Validated ReceiptApiVO vo) {
        return appUserApiService.userWithdrawal(vo);
    }

    @Log("我的客户")
    @GetMapping("/user/get-user-customer")
    public ApiResponseEntity getUserCustomer(@Validated AppUserVo vo) {
        return appUserApiService.getCustomer(vo);
    }

    @Log("我的团队")
    @GetMapping("/user/get-user-team")
    public ApiResponseEntity getUserTeam(@Validated AppUserVo vo) {
        return appUserApiService.getTeam(vo);
    }
}
